package com.dyz.leetcode;

import java.util.ArrayList;
import java.util.List;

public class Subsets78 {
    public static void main(String[] args) {
        int [] nums = new int[]{1,2,3};
        List<List<Integer>> subsets = new Subsets78().subsets(nums);
    }
    List<List<Integer>> res = new ArrayList<List<Integer>>();
    List<Integer> list = new ArrayList<Integer>();
    public List<List<Integer>> subsets(int[] nums) {

        //空的数组加进去
        res.add(new ArrayList<>());

        //递归
        dfs(nums, 0);
        return res;
    }
    private void dfs(int[] nums, int start){
        if(start>=nums.length){
            return;
        }

        for(int i=start; i<nums.length;i++){
            list.add(nums[i]);
            res.add(new ArrayList<>(list));
            dfs(nums, i+1);
            list.remove(list.size()-1);
        }
    }
}
